package com.dure.hotmemory.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.dure.hotmemory.R;


public class ShowSelectPictureDialogUtil {

    private View view;
    private Dialog dialog;
    private Button takePhotoBtn;
    private Button photoAlbumBtn;
    private Button cancelBtn;
    private SelectPictureInterface selectPictureInterface;

    public ShowSelectPictureDialogUtil(Context context, SelectPictureInterface selectPictureInterface) {
        this.selectPictureInterface = selectPictureInterface;
        view = LayoutInflater.from(context).inflate(R.layout.picture_select_way_layout, null);
        takePhotoBtn = (Button) view.findViewById(R.id.take_photo_btn);
        photoAlbumBtn = (Button) view.findViewById(R.id.photo_album_btn);
        cancelBtn = (Button) view.findViewById(R.id.cancel);



        dialog = new Dialog(context, R.style.customDialog);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        Window window = dialog.getWindow();
//		window.setWindowAnimations(R.anim.push_bottom_in);
        window.setGravity(Gravity.BOTTOM); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.mystyle); // 添加动画
        dialog.addContentView(view, lp);
    }

    public void show() {
        takePhotoBtn.setOnClickListener(new OnClickListener() {//拍照
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                selectPictureInterface.takePhoto();
                dialog.dismiss();
            }
        });
        photoAlbumBtn.setOnClickListener(new OnClickListener() {//手机相册

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                selectPictureInterface.takePhotoAlbum();
                dialog.dismiss();
            }
        });

        cancelBtn.setOnClickListener(new OnClickListener() {//取消

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });

        if (dialog != null) {
            if (!dialog.isShowing()) {
                dialog.show();
            } else {
                dialog.dismiss();
            }
        }
    }

    public void dismiss() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }


    public interface SelectPictureInterface {
        void takePhoto();

        void takePhotoAlbum();
    }
}
